<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增题目')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-question-add">
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">题库分类：</label>
                        <div class="col-sm-9">
                            <select name="typeId" class="form-control" required>
                                <option value="">请选择</option>
                                <option th:each="type:${typeList}" th:text="${type.name}" th:value="${type.id}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">类型：</label>
                        <div class="col-sm-9">
                            <select id="questionType" name="questionType" class="form-control m-b" th:with="type=${@dict.getType('tb_question_type')}" onchange="getType();" required>
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-1 control-label">题目：</label>
                        <div class="col-sm-10">
                            <textarea name="title" class="form-control" rows="3" required></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div id="select">
            <h3 style="color:#6379bb;margin:8px 10px 20px 70px;">选项:</h3>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">A：</label>
                        <div class="col-sm-9">
                            <input name="answerA" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">B：</label>
                        <div class="col-sm-9">
                            <input name="answerB" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row" id="pd">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">C：</label>
                        <div class="col-sm-9">
                            <input name="answerC" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">D：</label>
                        <div class="col-sm-9">
                            <input name="answerD" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-1 control-label">答案：</label>
                        <div class="col-sm-10">
                            <textarea id="answer" name="answer" class="form-control" placeholder="请输入A B C D" required></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-1 control-label">解析：</label>
                        <div class="col-sm-10">
                            <textarea name="introduce" class="form-control" rows="8"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">分数：</label>
                        <div class="col-sm-8">
                            <input name="score" class="form-control" type="number" required>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "module/question"
        $("#form-question-add").validate({
            focusCleanup: true
        });
        
        function getType() {
            var typeId = $("#questionType").find("option:selected").val();
            if(typeId == '4'){ //简答题
               $("#select").hide();
               $("#answer").attr("placeholder","");
            } else if(typeId=='2'){ //判断题
                $("#pd").hide();
            } else {
                $("#pd").show();
                $("#select").show();
                $("#answer").attr("placeholder","请输入A B C D");
            }
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-question-add').serialize());
            }
        }
    </script>
</body>
</html>